package com.answer.petadoption.mapper;

import com.answer.petadoption.model.entity.Animal;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface AnimalMapper {
    @Select("SELECT * FROM animal WHERE id = #{id}")
    Animal getAnimalById(Long id);

    @Select("SELECT * FROM animal WHERE name = #{name}")
    List<Animal> getAnimalsByName(String name);

    @Select("SELECT * FROM animal WHERE species = #{species}")
    List<Animal> getAnimalsBySpecies(String species);

    @Insert("INSERT INTO animal (name, species, age, gender, description, health_status, adoption_status, image_url, created_time, updated_time, deleted_time, breed, userId) "
            + "VALUES (#{name}, #{species}, #{age}, #{gender}, #{description}, #{healthStatus}, #{adoptionStatus}, #{imageUrl}, #{createdTime}, #{updatedTime}, #{deletedTime}, #{breed}, #{userId})")
    void insertAnimal(Animal animal);

    @Update("UPDATE animal SET name = #{name}, species = #{species}, age = #{age}, gender = #{gender}, description = #{description}, health_status = #{healthStatus}, "
            + "adoption_status = #{adoptionStatus}, image_url = #{imageUrl}, updated_time = #{updatedTime}, deleted_time = #{deletedTime}, breed = #{breed}, userId = #{userId} WHERE id = #{id}")
    void updateAnimal(Animal animal);

    @Update("UPDATE animal SET deleted_time = NOW() WHERE id = #{id}")
    void deleteAnimal(Long id);
}